package boerse.main;

import boerse.CommandProcessor.UniversalCommandProcessor;
import boerse.main.Account.AccountManager;
import boerse.main.Account.AccountManagerProxy;
import boerse.main.Asset.Share;
import boerse.main.Gui.GuiLoader;
import boerse.main.Gui.GuiLoaderImpl;
import boerse.main.Gui.MainWindow;
import boerse.main.StockPriceProvider.HistoricalStockPriceProvider;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.logging.LogManager;

import javafx.application.Application;
import javafx.stage.Stage;


public class StockGameLauncher extends Application {
	
	public static void main(String[] args) throws IOException{
		Application.launch();
	}

	@Override
	public void start(Stage stage) throws Exception {
//		RandomStockPriceProvider randomProvider = new RandomStockPriceProvider();
//		ConstStockPriceProvider constProvider = new ConstStockPriceProvider();
//      DynamicRandomStockPriceProvider randomProvider = new DynamicRandomStockPriceProvider();
        HistoricalStockPriceProvider randomProvider = new HistoricalStockPriceProvider();
       /* Share[] addShare = {new Share("bmw", 250), new Share("kuka", 204), new Share("mercedes", 219),
			new Share("nestle", 123), new Share("fca", 22), new Share("fcb", 151),
            new Share("vfb", 97), new Share("bvb", 123)};
         */

        LogManager.getLogManager().readConfiguration(new BufferedInputStream(new FileInputStream("c:\\logging.properties")));

        Share[] addShare = {new Share("bmw",100, "bmw.csv"), new Share("kuka", 100, "ku2.csv"), new Share("mercedes", 100, "ddaiy.csv"),
                new Share("nestle", 100, "nesr.csv"), new Share("toyota", 100, "tm.csv"), new Share("audi", 100, "nsu.csv"),
                new Share("vw", 100, "vow.csv"), new Share("bvb", 100, "bvb.csv")};

        randomProvider.addShare(addShare);
        randomProvider.historicalSetup();

        GuiLoaderImpl gui = new GuiLoaderImpl(randomProvider);
        
        Language language = new Language();
		AccountManager accountManager = new AccountManagerProxy(randomProvider, language.getResourceBundle(), language.getLocale());
		
		Class<?>[] allInterf = {AccountManager.class, GuiLoader.class};
		Object[] allObject = {accountManager, gui};

        final UniversalCommandProcessor cmdProcessor = new UniversalCommandProcessor(allObject,allInterf);
		
        MainWindow mainWindow = new MainWindow(accountManager, stage);
        
		new Thread(new Runnable() {
			public void run() {
				cmdProcessor.process();
			}
		}).start();
		
		
		
	}
	 
}
